/* file version: 1497608811_255026d57d0237e2b22fc4125a2d5628 */
BaseJS.addModuleClass("Common", {
    init: function() {
        this.renderBody("common");
    },
    actionMessage: function() {
        this.setPageTitle(this.initData.pageTitle || "系统提示");
        var tpl = this.getTpl("common", "message");
        var html = this.renderTpl(tpl, {
            info: this.initData.info
        });
        this.fillMainContent(html);
    },
    getPcUrl: function() {
        return window.location.protocol + "//" + window.location.host.replace(/^m\.(.*?)$/, "www.$1") + "/?desktop=true";
    },
    actionHome: function() {
        this.setPageTitle(MainJS.cfg.siteTitle || "");
        var data = MainJS.cfg.data;
        if (!data.lunbo || data.lunbo.length === 0) {
            data.lunbo = this.sysCfg.defaultLunbo;
        }
        if (!data.logo) {
            data.logo = this.sysCfg.defaultLogo;
        }
        var tpl = this.getTpl("common", "home");
        var html = this.renderTpl(tpl, data);
        this.fillMainContent(html);
        this.initCarousel();
        this.find(".menu-btn-area a").click(function(e) {
            MainJS.checkClick(this, e);
        });
        var _this = this;
        var info = _this.find(".notice-area .info");
        var infoW = 0;
        this.on("syncSize",
        function() {
            if (infoW > 0) {
                var animationDuration = Math.ceil((infoW + window.innerWidth) / 36) + "s";
                info[0].style.webkitAnimation = "scroll-left " + animationDuration + " linear infinite";
                info[0].style.animation = "scroll-left " + animationDuration + " linear infinite";
            }
            var minHeight = _this.getBodyMain().innerHeight() - _this.find(".page-top-area").outerHeight() - _this.find(".carousel-container").outerHeight() - _this.find(".notice-area").outerHeight();
            if (minHeight > 0) {
                this.find(".menu-btn-area").css("min-height", minHeight + "px");
            } else {
                this.find(".menu-btn-area").css("min-height", "");
            }
            var btnImgs = this.find(".menu-btn-area .menu-btn img");
            btnImgs.css("min-height", btnImgs.width() * (105 / 158));
        });
        this.requestGet("/index/webcom", null,
        function(data) {
            var topContainer = _this.find(".top-container");
            if (topContainer.length > 0) {
                var tpl = _this.getTpl("common", "loginInfo");
                var html = _this.renderTpl(tpl, data);
                topContainer.append(html);
            }
            info.css({
                display: "inline-block",
                width: "30000px"
            });
            var infoTxt = info.find(".info-txt");
            infoTxt.text(data.notice || "");
            infoW = infoTxt.width();
            infoTxt.css({
                display: "inline-block",
                width: infoW + "px",
                "font-size": "14px"
            });
            info.css({
                display: "",
                width: ""
            });
            _this.syncSize();
        },
        {
            noMask: true
        });
        if (data.lunbo) {
            var carouselContainer = this.find(".carousel-container");
            var loadCount = 0;
            carouselContainer.find("img").on("load",
            function() {
                loadCount++;
                if (loadCount >= data.lunbo.length) {
                    carouselContainer.css("height", "auto");
                }
            });
        }
        if (MainJS.isApp) {
            MainJS.setWindowShow({
                showLogo: "1",
                orientation: "s"
            });
        }
    },
    initCarousel: function() {
        var pX = 0;
        var moving = false;
        this.find(".carousel.slide").on("touchstart mousedown",
        function(event) {
            var originalEvent = event.originalEvent;
            var e = originalEvent.touches ? originalEvent.touches[0] : originalEvent;
            pX = e.pageX;
            moving = false;
            e.preventDefault();
        }).on("touchmove mouseup",
        function(event) {
            if (moving) {
                return;
            }
            moving = true;
            var originalEvent = event.originalEvent;
            var e = originalEvent.touches ? originalEvent.touches[0] : originalEvent;
            var diffX = e.pageX - pX;
            if (diffX > 5) {
                $(this).carousel("prev");
            }
            if (diffX < -5) {
                $(this).carousel("next");
            }
            e.preventDefault();
        }).on("touchend touchcancel mouseup",
        function() {
            moving = false;
        });
    },
    actionMoreMenu: function() {
        this.setPageTitle("娱乐中心");
        var tpl = this.getTpl("common", "moreMenu");
        var html = this.renderTpl(tpl, {
            secondMenu: MainJS.cfg.data.config.secondMenu
        });
        this.fillMainContent(html);
        this.find(".menu-btn-area .list-group-item >a").click(function(e) {
            MainJS.checkClick(this, e);
        });
    },
    actionOpenLink: function() {
        this.createBodyMainScrollbar = null;
        var tpl = this.getTpl("common", "iframePanel");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
        var iframe = this.find("iframe");
        var _this = this;
        _this.showMask();
        iframe.on("load",
        function() {
            _this.hideMask();
        });
        iframe[0].src = this.initData.url;
        this.on("syncSize",
        function() {
            _this.find("iframe").height(_this.getBodyMain().height());
        });
        this.syncSize();
    },
    actionOpenInApp: function() {
        if (MainJS.isApp) {
            MainJS.openInApp(this.initData.url);
        } else {
            var _this = this;
            setTimeout(function() {
                MainJS.openLink(_this.initData.url);
            },
            100);
        }
        this.remove();
    },
    actionLocation: function() {
        window.location = this.initData.url;
    },
    actionMemberMenu: function() {
        var menus = {
            name: "会员中心",
            childMenu: [{
                iconClass: "glyphicon glyphicon-user",
                name: "会员信息",
                url: "#module/member",
                login: "1",
                mode: "main"
            },
            {
                iconClass: "glyphicon glyphicon-usd",
                name: "资金流水",
                url: "#module/memberMoney",
                login: "1",
                mode: "main"
            },
            {
                iconClass: "glyphicon glyphicon-list-alt",
                name: "注单查询",
                url: "#module/memberBet",
                login: "1",
                mode: "main"
            },
            {
                iconClass: "glyphicon glyphicon-bell",
                name: "消息中心",
                url: "#module/memberMessage",
                login: "1",
                mode: "main"
            }]
        };
        this.setPageTitle(menus.name);
        var tpl = this.getTpl("common", "menuArea");
        var html = this.renderTpl(tpl, {
            menus: menus
        });
        this.fillMainContent(html);
        this.find(".menu-list a").click(function(e) {
            MainJS.checkClick(this, e);
        });
    },
    actionMoneyMenu: function() {
        var menus = {
            name: "充值提现",
            childMenu: [{
                iconClass: "glyphicon glyphicon-piggy-bank",
                name: "在线存款",
                url: "#module/member/action/recharge",
                login: "1",
                mode: "main"
            },
            {
                iconClass: "glyphicon glyphicon-new-window",
                name: "在线取款",
                url: "#module/member/action/draw",
                login: "1",
                mode: "main"
            }]
        };
        this.setPageTitle(menus.name);
        var tpl = this.getTpl("common", "menuArea");
        var html = this.renderTpl(tpl, {
            menus: menus
        });
        this.fillMainContent(html);
        this.find(".menu-list a").click(function(e) {
            MainJS.checkClick(this, e);
        });
    },
    actionDownload: function() {
        this.setPageTitle("客户端下载");
        var tpl = this.getTpl("common", "appQRCode");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
    },
    actionMenuLink: function() {
        if (MainJS.isUnloading) {
            showAlert("页面加载中，请稍后再试");
            return;
        }
        var menuType = this.initData.menu;
        var id = this.initData.id;
        var link = $("<a></a>");
        var menu = MainJS.cfg.data.config[menuType];
        var linkItem = null;
        if (menu) {
            $.each(menu,
            function(k, v) {
                if (id === v.id) {
                    linkItem = v;
                    return false;
                }
                if (v.sub) {
                    $.each(v.sub,
                    function(k1, v1) {
                        if (id === v1.id) {
                            linkItem = v1;
                            return false;
                        }
                    });
                }
            });
        }
        if (!linkItem) {
            return;
        }
        link.data("item", linkItem);
        MainJS.checkClick(link[0]);
        this.remove();
    },
    actionExchange: function() {
        var target = this.initData.target;
        var url = this.initData.url;
        this.requestGet("/exchange/balance/" + target, null,
        function(data) {
            var info = data[target];
            if (info >= 1 || info === "刷新重试!") {
                window.location = url;
            } else {
                var dialog = MainJS.showExchangeDialog(target,
                function() {
                    window.location = url;
                });
                dialog.find(".modal-header .close").click(function() {
                    window.close();
                });
            }
        },
        {
            error: function() {
                window.location = url;
            }
        });
    }
});;
BaseJS.addModuleClass("Game", {
    init: function() {
        this.initData.source = this.initData.source || "hb";
        this.renderBody("game");
    },
    actionIndex: function() {
        if (this.initData.app) {
            var _this = this;
            this.requestGet("/" + this.initData.app + "/app", null,
            function(data) {
                _this.openApp(data);
            });
            return;
        }
        this.setPageTitle("全部游戏");
        this.currentGameType = "all";
        this.currentGameIndex = 0;
        this.games = [];
        this.typeGames = [];
        this.openMode = null;
        var _this = this;
        this.requestGet("/" + this.initData.source + "/game", null,
        function(data) {
            _this.games = data.games || [];
            _this.typeGames = _this.games;
            _this.openMode = data.mode;
            _this.getGameList();
            _this.initMenu(data.types);
        });
        this.getBodyMain().on("click", ".game-item a",
        function() {
            if ($(this).data("item")) {
                MainJS.checkClick(this);
                return;
            }
            var url = this.href;
            if (_this.sysCfg.isOpenLocation) {
                window.location = url;
            } else {
                MainJS.openWin(url, $.trim($(this).find(".game-name").text()), {
                    orientation: "h"
                });
            }
            return false;
        });
        this.getPullUpHandler = function() {
            if (!this.pullUpHandler) {
                this.pullUpHandler = function() {
                    _this.getGameList();
                };
            }
            return this.pullUpHandler;
        };
    },
    openApp: function(data) {
        this.setPageTitle(data.gameName);
        if (!BaseJS.isMac && !BaseJS.isAndroid) {
            showAlert("该游戏暂不支持您使用的操作系统",
            function() {
                MainJS.goBack();
            });
            return;
        }
        var tpl = this.getTpl("game", "openApp");
        var app = BaseJS.isMac ? data.IOS: data.Android;
        var html = this.renderTpl(tpl, {
            downloadUrl: data.Download,
            app: app,
            notice: this.getAppNotice(this.initData.app)
        });
        this.fillMainContent(html);
        if (this.sysCfg.openAppMethod === "openApp") {
            MainJS.openApp(app);
        } else {
            window.location = app;
        }
    },
    getAppNotice: function(app) {
        var notices = {
            ab: "提示：请先安装欧博APP，安装成功后，点击下方“启动游戏”按钮启动游戏，暂无法通过欧博APP直接登录账号游戏！"
        };
        return notices[app] || "";
    },
    getGameList: function(type) {
        var mainContainer = this.find(".main-container");
        var pullUp = this.find(".pull-up");
        var _this = this;
        if (type && this.currentGameType !== type) {
            this.currentGameType = type;
            this.currentGameIndex = 0;
            mainContainer.empty();
            pullUp.show();
            this.typeGames = [];
            if (this.currentGameType === "all") {
                this.typeGames = this.games;
            } else {
                $.each(this.games,
                function(k, v) {
                    if (v.gameType == _this.currentGameType) {
                        _this.typeGames.push(v);
                    }
                });
            }
        }
        if (this.typeGames.length === 0) {
            mainContainer.html('<div class="no-result">没有相关游戏</div>');
            pullUp.hide();
            return;
        }
        var showGames = [];
        $.each(this.typeGames,
        function(k, v) {
            if (k >= _this.currentGameIndex) {
                if (_this.openMode && !v.openMode) {
                    v.openMode = $.extend({
                        name: v.gameName,
                        url: v.playUrl
                    },
                    _this.openMode);
                }
                showGames.push(v);
                _this.currentGameIndex++;
            }
            if (showGames.length >= 24) {
                return false;
            }
        });
        if (showGames.length > 0) {
            var tpl = _this.getTpl("game", "list");
            var html = _this.renderTpl(tpl, {
                itemList: showGames
            });
            mainContainer.append(html);
            if (this.currentGameIndex >= this.typeGames.length) {
                mainContainer.append('<div class="no-result">已没有更多</div>');
                pullUp.hide();
            }
        }
    },
    initMenu: function(menuItems) {
        menuItems = menuItems || [];
        var tpl = this.getTpl("game", "dropMenu");
        var html = this.renderTpl(tpl, {
            menuItems: menuItems
        });
        var dropdownMenu = this.find(".main-menu-btn .dropdown-menu");
        dropdownMenu.html(html);
        var _this = this;
        dropdownMenu.find("li>a").click(function() {
            var menuItem = $(this);
            var type = menuItem.data("type");
            _this.setPageTitle(menuItem.text());
            _this.getGameList(type);
        });
    }
});;
BaseJS.addModuleClass("Member", {
    init: function() {
        this.renderBody("member");
    },
    actionIndex: function() {
        this.setPageTitle("会员中心");
        this.initPullDownRefresh();
        var url = "/member/index";
        var _this = this;
        this.requestGet(url, null,
        function(data) {
            var tpl = _this.getTpl("member", "mainIndex");
            var html = _this.renderTpl(tpl, {
                info: data
            });
            _this.fillMainContent(html);
            _this.find(".bank-btn").click(function() {
                MainJS.openModule("member", {
                    action: "bank"
                });
            });
        });
    },
    actionBank: function() {
        this.setPageTitle(this.initData.type === "complete" ? "完善资料": "绑定银行");
        var tpl = this.getTpl("member", "bank");
        var _this = this;
        this.requestGet("/member/index", null,
        function(data) {
            if (data.realname && data.bank && data.bank_account) {
                showAlert("您的个人信息已完善，无需再填写。",
                function() {
                    window.history.back();
                });
                return;
            }
            var html = _this.renderTpl(tpl, {
                memberInfo: data
            });
            _this.fillMainContent(html);
            _this.find(".submit-btn").click(function() {
                var bank = _this.find("[name='bank']").val();
                var bankaccount = _this.find("[name='bank_account']").val();
                var realname = _this.find("[name='realname']").val();
                if (!realname) {
                    showAlert("请输入真实姓名",
                    function() {
                        _this.find("[name='realname']").focus();
                    });
                    return;
                }
                if (!bank) {
                    showAlert("请输入开户银行",
                    function() {
                        _this.find("[name='bank']").focus();
                    });
                    return;
                }
                if (!bankaccount) {
                    showAlert("请输入银行账号",
                    function() {
                        _this.find("[name='bank_account']").focus();
                    });
                    return;
                }
                _this.requestPost("/member/addinfo", {
                    bank: bank,
                    bank_account: bankaccount,
                    realname: realname
                });
            });
        });
    },
    actionPassword: function() {
        this.setPageTitle("修改密码");
        var tpl = this.getTpl("member", "password");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
        var _this = this;
        this.find(".submit-btn").click(function() {
            var oldpassword = _this.find("[name='oldpassword']").val();
            var password = _this.find("[name='password']").val();
            var repassword = _this.find("[name='repassword']").val();
            if (!oldpassword) {
                showAlert("请输入旧密码",
                function() {
                    _this.find("[name='oldpassword']").focus();
                });
                return;
            }
            if (!password) {
                showAlert("请输入新密码",
                function() {
                    _this.find("[name='password']").focus();
                });
                return;
            }
            var newpasswordlenght = password.length;
            if (newpasswordlenght < 6 || newpasswordlenght > 20) {
                showAlert("新密码在6-20个字符之间",
                function() {
                    _this.find("[name='password']").focus();
                });
                return;
            }
            if (!repassword) {
                showAlert("请输入确认新密码",
                function() {
                    _this.find("[name='repassword']").focus();
                });
                return;
            }
            if (password != repassword) {
                showAlert("两次输入的新密码不一致",
                function() {
                    _this.find("[name='repassword']").focus();
                });
                return;
            }
            _this.requestPost("/member/password", {
                oldpassword: oldpassword,
                password: password,
                repassword: repassword
            });
        });
    },
    actionQkmm: function() {
        this.setPageTitle("修改密码");
        var _this = this;
        this.requestGet("/member/index", null,
        function(data) {
            if (data.isSetqkmm == "1") {
                _this.find(".qkmm-tab-title").text("修改取款密码");
            } else {
                _this.find(".qkmm-tab-title").text("设置取款密码");
            }
            _this.find(".top-menu-area").show();
            var tpl = _this.getTpl("member", "qkmm");
            var html = _this.renderTpl(tpl, {
                memberInfo: data
            });
            _this.fillMainContent(html);
            _this.find(".submit-btn").click(function() {
                var oldpasswordInput = _this.find("[name='oldpassword']");
                var hasOld = oldpasswordInput.length > 0 ? true: false;
                var oldpassword = oldpasswordInput.val();
                var qkmm = _this.find("[name='qkmm']").val();
                var reqkmm = _this.find("[name='reqkmm']").val();
                if (hasOld && !oldpassword) {
                    showAlert("请输入旧密码",
                    function() {
                        _this.find("[name='oldpassword']").focus();
                    });
                    return;
                }
                if (!qkmm) {
                    showAlert("请输入" + (hasOld ? "新": "") + "密码",
                    function() {
                        _this.find("[name='qkmm']").focus();
                    });
                    return;
                }
                var newqkmmlenght = qkmm.length;
                if (newqkmmlenght < 6 || newqkmmlenght > 20) {
                    showAlert((hasOld ? "新": "") + "密码在6-20个字符之间",
                    function() {
                        _this.find("[name='qkmm']").focus();
                    });
                    return;
                }
                if (!reqkmm) {
                    showAlert("请输入确认" + (hasOld ? "新": "") + "密码",
                    function() {
                        _this.find("[name='reqkmm']").focus();
                    });
                    return;
                }
                if (qkmm != reqkmm) {
                    showAlert("两次输入的" + (hasOld ? "新": "") + "密码不一致",
                    function() {
                        _this.find("[name='reqkmm']").focus();
                    });
                    return;
                }
                var sendData = {
                    qkmm: qkmm,
                    reqkmm: reqkmm
                };
                if (hasOld) {
                    sendData.oldpassword = oldpassword;
                }
                _this.requestPost("/member/qkmm", sendData);
            });
        });
    },
    actionDraw: function() {
        this.setPageTitle("在线取款");
        var _this = this;
        this.requestGet("/member/draw", null,
        function(data) {
            var tpl = _this.getTpl("member", "draw");
            var html = _this.renderTpl(tpl, {
                drawData: data
            });
            _this.fillMainContent(html);
            _this.find(".submit-btn").click(function() {
                var bankInput = _this.find("[name='bank']");
                var bank = bankInput.val();
                var bankAccountInput = _this.find("[name='bank_account']");
                var bankAccount = bankAccountInput.val();
                var amountInput = _this.find("[name='amount']");
                var amount = Number(amountInput.val());
                var qkmmInput = _this.find("[name='qkmm']");
                var qkmm = qkmmInput.val();
                if (!bank) {
                    showAlert("请输入开户银行",
                    function() {
                        bankInput.focus();
                    });
                    return;
                }
                if (!bankAccount) {
                    showAlert("请输入银行账号",
                    function() {
                        bankAccountInput.focus();
                    });
                    return;
                }
                if (!$.isNumeric(amount) || amount <= 0) {
                    showAlert("请输入正确的提款金额",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                if (amount < 100) {
                    showAlert("提款金额不能低于100元",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                if (amount > Number(data.money)) {
                    showAlert("提款金额不能超过可用余额",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                if (!qkmm) {
                    showAlert("请输入提款密码",
                    function() {
                        qkmmInput.focus();
                    });
                    return;
                }
                _this.requestPost("/member/draw", {
                    bank: bank,
                    bank_account: bankAccount,
                    amount: amount,
                    qkmm: qkmm
                });
            });
        });
    },
    actionRecharge: function() {
        this.setPageTitle("选择存款方式");
        var tpl = this.getTpl("member", "recharge");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
    },
    actionRechargeBank: function() {
        this.setPageTitle("选择银行账号");
        var _this = this;
        this.requestGet("/member/recharge/company?step=1", null,
        function(data) {
            var tpl = _this.getTpl("member", "rechargeBank");
            var html = _this.renderTpl(tpl, {
                rechargeInfoList: data.banks || []
            });
            _this.fillMainContent(html);
            _this.find(".list-group-item").click(function() {
                var info = $(this).data("info");
                MainJS.openModule("member", $.extend({
                    action: "doRechargeBank",
                    bankMinAmount: data.amountLimit.bankMinAmount,
                    bankMaxAmount: data.amountLimit.bankMaxAmount
                },
                info));
            });
        });
    },
    actionDoRecharge: function() {
        var payment = this.initData.payment;
        if (payment === "alipay") {
            this.setPageTitle("支付宝转账");
        }
        if (payment === "weixin") {
            this.setPageTitle("微信转账");
        }
        if (payment === "tenpay") {
            this.setPageTitle("财付通转账");
        }
        if (payment === "epay") {
            this.setPageTitle("在线支付");
        }
        var _this = this;
        this.requestGet("/member/payment/" + payment, null,
        function(data) {
            var tpl = _this.getTpl("member", "doRecharge");
            var html = _this.renderTpl(tpl, {
                rechargeInfo: data,
                rtime: MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd"),
                payment: payment
            });
            _this.fillMainContent(html);
            _this.find(".submit-btn").click(function() {
                var realnameInput = _this.find("[name='realname']");
                var amountInput = _this.find("[name='amount']");
                var rtimeInput = _this.find("[name='rtime']");
                var accountInput = _this.find("[name='account']");
                var realname = realnameInput.val();
                var amount = Number(amountInput.val());
                var rtime = rtimeInput.val();
                var account = accountInput.val();
                if (!realname) {
                    showAlert("请输入支付户名",
                    function() {
                        realnameInput.focus();
                    });
                    return;
                }
                if (accountInput.length > 0) {
                    if (!amount) {
                        showAlert("请输入支付账号",
                        function() {
                            accountInput.focus();
                        });
                        return;
                    }
                }
                if (!$.isNumeric(amount) || amount <= 0) {
                    showAlert("请输入正确的存款金额",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                var min = Number(data.min);
                if (min > 0 && amount < min) {
                    showAlert("存款金额不能低于" + min + "元",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                var max = Number(data.max);
                if (max > 0 && amount > max) {
                    showAlert("存款金额不能超过" + max + "元",
                    function() {
                        amountInput.focus();
                    });
                    return;
                }
                if (!rtime) {
                    showAlert("存款时间不能为空",
                    function() {
                        rtimeInput.focus();
                    });
                    return;
                }
                _this.requestPost("/member/payment/" + payment, {
                    realname: realname,
                    account: account,
                    amount: amount,
                    rtime: rtime,
                    wantGift: _this.find("[name='wantGift']").val()
                });
            });
        });
    },
    actionDoRechargeBank: function() {
        this.setPageTitle("填写存款信息");
        var tpl = this.getTpl("member", "doRechargeBank");
        var html = this.renderTpl(tpl, {
            rtime: MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd")
        });
        this.fillMainContent(html);
        var _this = this;
        this.find(".submit-btn").click(function() {
            var realnameInput = _this.find("[name='realname']");
            var accountInput = _this.find("[name='account']");
            var amountInput = _this.find("[name='amount']");
            var rtimeInput = _this.find("[name='rtime']");
            var realname = realnameInput.val();
            var account = accountInput.val();
            var amount = amountInput.val();
            var rtime = rtimeInput.val();
            if (!realname) {
                showAlert("请输入存款人姓名",
                function() {
                    realnameInput.focus();
                });
                return;
            }
            if (!account) {
                showAlert("请输入支付账号",
                function() {
                    accountInput.focus();
                });
                return;
            }
            if (!$.isNumeric(amount) || amount <= 0) {
                showAlert("请输入正确的存款金额",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var min = Number(_this.initData.bankMinAmount);
            if (min > 0 && amount < min) {
                showAlert("存款金额不能低于" + min + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var max = Number(_this.initData.bankMaxAmount);
            if (max > 0 && amount > max) {
                showAlert("存款金额不能超过" + max + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            if (!rtime) {
                showAlert("存款时间不能为空",
                function() {
                    rtimeInput.focus();
                });
                return;
            }
            _this.requestPost("/member/recharge/company?step=2", {
                bank_id: _this.initData.bid2,
                realname: realname,
                account: account,
                amount: amount,
                rtime: rtime,
                way: _this.find("[name='way']").val(),
                wantGift: _this.find("[name='wantGift']").val()
            });
        });
    },
    actionRechargeWeixin: function() {
        this.setPageTitle("微信转账");
        this.rechargeThirdParty("weixin");
    },
    actionRechargeAlipay: function() {
        this.setPageTitle("支付宝转账");
        this.rechargeThirdParty("alipay");
    },
    actionRechargeTenpay: function() {
        this.setPageTitle("财付通转账");
        this.rechargeThirdParty("tenpay");
    },
    actionRechargeEpay: function() {
        this.setPageTitle("在线支付");
        this.rechargeThirdParty("epay");
    },
    actionWaitTransfer: function() {
        this.setPageTitle("等待转账");
        var tpl = this.getTpl("member", "wait_transfer");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
    },
    showRechargePage: function(payment, data) {
        var tpl = this.getTpl("member", "doRecharge");
        var html = this.renderTpl(tpl, {
            rechargeInfo: data,
            rtime: MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd"),
            payment: payment
        });
        this.fillMainContent(html);
        var _this = this;
        this.find(".submit-btn").click(function() {
            var realnameInput = _this.find("[name='realname']");
            var amountInput = _this.find("[name='amount']");
            var rtimeInput = _this.find("[name='rtime']");
            var accountInput = _this.find("[name='account']");
            var realname = realnameInput.val();
            var amount = amountInput.val();
            var rtime = rtimeInput.val();
            var account = accountInput.val();
            if (!realname) {
                showAlert("请输入支付户名",
                function() {
                    realnameInput.focus();
                });
                return;
            }
            if (accountInput.length > 0) {
                if (!amount) {
                    showAlert("请输入支付账号",
                    function() {
                        accountInput.focus();
                    });
                    return;
                }
            }
            if (!$.isNumeric(amount) || amount <= 0) {
                showAlert("请输入正确的存款金额",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var min = Number(data.min);
            if (min > 0 && amount < min) {
                showAlert("存款金额不能低于" + min + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var max = Number(data.max);
            if (max > 0 && amount > max) {
                showAlert("存款金额不能超过" + max + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            if (!rtime) {
                showAlert("存款时间不能为空",
                function() {
                    rtimeInput.focus();
                });
                return;
            }
            _this.requestPost("/member/payment/" + payment, {
                realname: realname,
                account: account,
                amount: amount,
                rtime: rtime,
                wantGift: _this.find("[name='wantGift']").val()
            });
        });
    },
    showRechargeThirdParty: function(type, payment) {
        var tpl = this.getTpl("member", "rechargeThirdParty");
        var html = this.renderTpl(tpl, {
            payment: payment,
            type: type
        });
        this.fillMainContent(html);
        var _this = this;
        this.find(".submit-btn").click(function() {
            var amountInput = _this.find("[name='amount']");
            var amount = amountInput.val();
            if (!$.isNumeric(amount) || amount <= 0) {
                showAlert("请输入正确的存款金额",
                function() {
                    amountInput.focus();
                });
                return;
            }
            if (/\./.test(amount)) {
                showAlert("请输入整数的存款金额",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var min = Number(payment.payMinAmount);
            if (min > 0 && amount < min) {
                showAlert("存款金额不能低于" + min + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var max = Number(payment.payMaxAmount);
            if (max > 0 && amount > max) {
                showAlert("存款金额不能超过" + max + "元",
                function() {
                    amountInput.focus();
                });
                return;
            }
            var rechargeForm = _this.find("form.recharge");
            if (_this.sysCfg.isTransformNewWin) {
                rechargeForm[0].target = "_blank";
                setTimeout(function() {
                    MainJS.createModule("member", {
                        action: "waitTransfer"
                    });
                },
                2000);
            }
            rechargeForm.submit();
        });
    },
    openInApp: function(type, paymentItem) {
        var baseUrl = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port: "");
        var infoStr = "#module/member";
        $.each({
            action: "showRechargeItem",
            type: type,
            payWay: paymentItem.type,
            paymentItem: JSON.stringify(paymentItem)
        },
        function(key, val) {
            infoStr += "/" + encodeURIComponent(key) + "/" + encodeURIComponent(val);
        });
        var url = baseUrl + window.location.pathname + infoStr;
        MainJS.openInApp(url);
    },
    showRechargeAllList: function(type, paymentList) {
        var tpl = this.getTpl("member", "rechargeAllList");
        var html = this.renderTpl(tpl, {
            rechargeInfoList: paymentList || [],
            type: type
        });
        this.fillMainContent(html);
        var _this = this;
        this.find(".list-group-item").click(function() {
            var paymentItem = $(this).data("info");
            if (paymentItem.type === "way3" && MainJS.isApp) {
                _this.openInApp(type, paymentItem);
            } else {
                MainJS.openModule("member", {
                    action: "showRechargeItem",
                    type: type,
                    paymentItem: JSON.stringify(paymentItem)
                });
            }
        });
    },
    actionShowRechargeItem: function() {
        var type = this.initData.type;
        if (type === "alipay") {
            this.setPageTitle("支付宝转账");
        }
        if (type === "weixin") {
            this.setPageTitle("微信转账");
        }
        if (type === "tenpay") {
            this.setPageTitle("财付通转账");
        }
        if (type === "epay") {
            this.setPageTitle("在线支付");
        }
        var paymentItem = JSON.parse(this.initData.paymentItem);
        if (paymentItem.type === "way1") {
            this.showRechargePage(type, paymentItem.payment);
        } else {
            this.rechargeThirdParty(type, paymentItem.payment);
        }
    },
    rechargeThirdParty: function(type, payment) {
        var _this = this;
        if (payment) {
            this.showRechargeThirdParty(type, payment);
        } else {
            this.requestGet((type === "epay" ? "/member/": "/member/payment/") + type, null,
            function(data) {
                var paymentList = [];
                if (data["way3"]) {
                    if ($.isArray(data["way3"])) {
                        $.each(data["way3"],
                        function(k, v) {
                            paymentList.push({
                                type: "way3",
                                payment: v
                            });
                        });
                    } else {
                        paymentList.push({
                            type: "way3",
                            payment: data["way3"]
                        });
                    }
                }
                if (data["way1"]) {
                    if ($.isArray(data["way1"])) {
                        $.each(data["way1"],
                        function(k, v) {
                            paymentList.push({
                                type: "way1",
                                payment: v
                            });
                        });
                    } else {
                        paymentList.push({
                            type: "way1",
                            payment: data["way1"]
                        });
                    }
                }
                if (data["epay"]) {
                    paymentList.push({
                        type: "epay",
                        payment: data["epay"]
                    });
                }
                if (paymentList.length > 1) {
                    _this.showRechargeAllList(type, paymentList);
                } else {
                    var paymentItem = paymentList[0];
                    if (paymentItem.type === "way1") {
                        _this.showRechargePage(type, paymentItem.payment);
                    } else {
                        if (paymentItem.type === "way3" && MainJS.isApp) {
                            _this.openInApp(type, paymentItem);
                            MainJS.goBack();
                        } else {
                            _this.rechargeThirdParty(type, paymentItem.payment);
                        }
                    }
                }
            });
        }
    },
    actionLogin: function() {
        this.setPageTitle("用户登录");
        var tpl = this.getTpl("member", "login");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
        var _this = this;
        this.find(".submit-btn").click(function() {
            var usernameInput = _this.find("[name='username']");
            var passwordInput = _this.find("[name='password']");
            var username = usernameInput.val();
            var password = passwordInput.val();
            if (!username) {
                showAlert("用户名不能为空",
                function() {
                    usernameInput.focus();
                });
                return;
            }
            if (!password) {
                showAlert("密码不能为空",
                function() {
                    passwordInput.focus();
                });
                return;
            }
            _this.requestPost("/index/login", {
                username: username,
                password: password
            },
            function() {
                MainJS.setLoginState(true);
                showSuccess("登录成功",
                function() {
                    MainJS.goBack();
                });
            });
        });
    },
    actionRegister: function() {
        this.setPageTitle("用户注册");
        var _this = this;
        _this.requestGet("/index/register", null,
        function(data) {
            var tpl = _this.getTpl("member", "register");
            var captchaUrl = "/index/captcha";
            data.captchaUrl = captchaUrl + "?t=" + (new Date()).getTime();
            var html = _this.renderTpl(tpl, data);
            _this.fillMainContent(html);
            var captchaRefreshBtn = _this.find(".captcha-refresh-btn");
            var captchaImg = _this.find(".captcha-img");
            var captchaInput = _this.find("[name='captcha']");
            captchaRefreshBtn.click(function() {
                captchaImg.attr("src", captchaUrl + "?t=" + (new Date()).getTime());
            });
            _this.find(".submit-btn").click(function() {
                var usernameInput = _this.find("[name='username']");
                var passwordInput = _this.find("[name='password']");
                var repasswordInput = _this.find("[name='repassword']");
                var realnameInput = _this.find("[name='realname']");
                var qkmmInput = _this.find("[name='qkmm']");
                var qqInput = _this.find("[name='qq']");
                var telInput = _this.find("[name='tel']");
                var emailInput = _this.find("[name='email']");
                var questionSelect = _this.find("[name='question']");
                var answerInput = _this.find("[name='answer']");
                var tjidInput = _this.find("[name='tjid']");
                var username = usernameInput.val();
                var password = passwordInput.val();
                var repassword = repasswordInput.val();
                var realname = realnameInput.val();
                var qkmm = qkmmInput.val();
                var qq = qqInput.val();
                var tel = telInput.val();
                var email = emailInput.val();
                var captcha = captchaInput.val();
                var question = questionSelect.val();
                var answer = answerInput.val();
                var tjid = tjidInput.val();
                if (!username) {
                    showAlert("用户名不能为空",
                    function() {
                        usernameInput.focus();
                    });
                    return;
                }
                if (!password) {
                    showAlert("密码不能为空",
                    function() {
                        passwordInput.focus();
                    });
                    return;
                }
                if (password !== repassword) {
                    showAlert("两次密码不一致",
                    function() {
                        repasswordInput.focus();
                    });
                    return;
                }
                if (!realname) {
                    showAlert("真实姓名不能为空",
                    function() {
                        realnameInput.focus();
                    });
                    return;
                }
                if (!qkmm) {
                    showAlert("取款密码不能为空",
                    function() {
                        qkmmInput.focus();
                    });
                    return;
                }
                if (qqInput.length > 0 && qqInput[0].checkValidity && !qqInput[0].checkValidity()) {
                    showAlert("请填写正确的QQ号码",
                    function() {
                        qqInput.focus();
                    });
                    return;
                }
                if (qqInput.length > 0 && !qq) {
                    showAlert("QQ号码不能为空",
                    function() {
                        qqInput.focus();
                    });
                    return;
                }
                if (telInput.length > 0 && telInput[0].checkValidity && !telInput[0].checkValidity()) {
                    showAlert("请填写正确的手机号码",
                    function() {
                        telInput.focus();
                    });
                    return;
                }
                if (telInput.length > 0 && !tel) {
                    showAlert("手机号码不能为空",
                    function() {
                        telInput.focus();
                    });
                    return;
                }
                if (emailInput.length > 0 && emailInput[0].checkValidity && !emailInput[0].checkValidity()) {
                    showAlert("请填写正确的电子邮箱",
                    function() {
                        emailInput.focus();
                    });
                    return;
                }
                if (emailInput.length > 0 && !email) {
                    showAlert("电子邮箱不能为空",
                    function() {
                        emailInput.focus();
                    });
                    return;
                }
                if (!question) {
                    showAlert("请选择密码提示问题",
                    function() {
                        questionSelect.focus();
                    });
                    return;
                }
                if (!answer) {
                    showAlert("密码提示答案不能为空",
                    function() {
                        answerInput.focus();
                    });
                    return;
                }
                if (captchaInput.length > 0 && !captcha) {
                    showAlert("验证码不能为空",
                    function() {
                        captchaInput.focus();
                    });
                    return;
                }
                _this.requestPost("/index/register", {
                    username: username,
                    password: password,
                    repassword: repassword,
                    realname: realname,
                    qkmm: qkmm,
                    qq: qq,
                    tel: tel,
                    email: email,
                    question: question,
                    answer: answer,
                    tjid: tjid,
                    captcha: captcha
                },
                function() {
                    MainJS.setLoginState(true);
                    showSuccess("注册成功",
                    function() {
                        MainJS.goHome();
                    });
                },
                {
                    errorHandler: function() {
                        captchaRefreshBtn.click();
                        captchaInput.val("");
                    }
                });
            });
        });
    }
});;
BaseJS.addModuleClass("MemberBet", {
    init: function() {
        this.renderBody("member_bet");
    },
    actionIndex: function() {
        this.setPageTitle("请选择注单类别");
        var tpl = this.getTpl("member_bet", "mainMenu");
        var html = this.renderTpl(tpl);
        this.fillMainContent(html);
        this.find(".select-menu .btn").click(function() {
            var catalog = $(this).data("catalog");
            MainJS.openModule("memberBet", {
                action: "query",
                catalog: catalog
            });
        });
    },
    actionQuery: function() {
        var tpl = this.getTpl("member_bet", "query");
        var html = this.renderTpl(tpl, {
            startTime: MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd"),
            endTime: MainJS.getTimeForServer((new Date()).getTime() + 3600 * 24 * 1000, "yyyy-MM-dd")
        });
        this.fillMainContent(html);
        this.initSelect();
        var _this = this;
        this.find(".submit-btn").click(function() {
            var startTimeInput = _this.find("form [name='startTime']");
            var endTimeInput = _this.find("form [name='endTime']");
            var startTime = startTimeInput.val();
            var endTime = endTimeInput.val();
            if (!startTime) {
                showAlert("开始时间不能为空",
                function() {
                    startTimeInput.focus();
                });
                return;
            }
            if (!endTime) {
                showAlert("结束时间不能为空",
                function() {
                    endTimeInput.focus();
                });
                return;
            }
            MainJS.openModule("memberBet", {
                action: 'list',
                type: _this.find("form [name='type']").val(),
                startTime: startTime,
                endTime: endTime
            });
        });
    },
    getMenuItems: function(catalog) {
        var menuItems = [];
        $.each(MainJS.sysSetting.orderMenuItems || [],
        function(k, v) {
            if (v.id === catalog) {
                menuItems = v.items;
                return false;
            }
        });
        return menuItems;
    },
    initSelect: function() {
        var catalog = this.initData.catalog;
        var menu = this.find("form [name='type']");
        var tpl = this.getTpl("member_bet", "dropMenu");
        var menuItems = this.getMenuItems(catalog);
        var html = this.renderTpl(tpl, {
            menuItems: menuItems
        });
        var menuName = menuItems.length > 0 ? menuItems[0].name: "";
        this.setPageTitle(menuName + " 注单查询");
        menu.html(html);
        var _this = this;
        menu.change(function() {
            var menuName = _this.getMenuName($(this).val(), menuItems);
            _this.setPageTitle(menuName + " 注单查询");
        });
    },
    getMenuName: function(type, menuItems) {
        var menuName = "";
        $.each(menuItems,
        function(k, v) {
            if (v.id === type) {
                menuName = v.name;
                return false;
            }
        });
        return menuName;
    },
    getBetList: function() {
        var type = this.initData.type;
        var url = "";
        if (this.betListPageInfo) {
            if (this.betListCurrentPage >= this.betListPageInfo.page) {
                return;
            }
        }
        if (this.betListPageInfo && this.betListCurrentPage > 0) {
            url = "/bet/" + type + "/_page-" + (this.betListCurrentPage + 1) + "-" + this.betListPageInfo.total + "_";
        } else {
            url = "/bet/" + type;
        }
        var _this = this;
        this.requestGet(url, {
            startTime: this.initData.startTime,
            endTime: this.initData.endTime
        },
        function(data) {
            var tpl = _this.getTpl("member_bet", "list");
            var html = _this.renderTpl(tpl, {
                list: data.bets,
                detail: data.detail
            });
            _this.betListPageInfo = {
                page: data.page,
                total: data.total
            };
            if (_this.betListCurrentPage > 0) {
                _this.betListCurrentPage++;
            } else {
                _this.betListCurrentPage = 1;
            }
            if (_this.betListCurrentPage === 1 && data.bets.length === 0) {
                html = '<div class="no-result">没有相关信息</div>';
                _this.find(".pull-up").hide();
            } else {
                if (_this.betListCurrentPage >= _this.betListPageInfo.page) {
                    html += '<div class="no-result">已没有更多</div>';
                    _this.find(".pull-up").hide();
                }
            }
            _this.appendMainContent(html);
            _this.countAmountList();
        });
    },
    countAmountList: function() {
        var totalBetAmount = 0;
        var totalBetResult = 0;
        this.find(".list-group-item .bet-amount").each(function() {
            totalBetAmount += Number($(this).data("amount"));
        });
        this.find(".list-group-item .net-amount").each(function() {
            totalBetResult += Number($(this).data("amount"));
        });
        this.find(".total-bet-amount").text(BaseJS.formatMoney(totalBetAmount));
        this.find(".total-bet-result").text(BaseJS.formatMoney(totalBetResult));
    },
    actionList: function() {
        this.setPageTitle("注单列表");
        this.initPullDownRefresh();
        this.getBetList();
        var _this = this;
        this.getPullUpHandler = function() {
            if (!this.pullUpHandler) {
                this.pullUpHandler = function() {
                    _this.getBetList();
                };
            }
            return this.pullUpHandler;
        };
        this.getBodyMain().on("click", ".list-group-item",
        function() {
            $(this).find(".detail").toggle();
        });
    }
});;
BaseJS.addModuleClass("MemberExchange", {
    init: function() {
        this.tplId = this.sysCfg.tplId || "member_exchange";
        this.renderBody(this.tplId);
    },
    actionIndex: function() {
        this.setPageTitle("额度转换");
        var _this = this;
        this.requestGet("/exchange", null,
        function(data) {
            var tpl = _this.getTpl(_this.tplId, "exchangeArea");
            var html = _this.renderTpl(tpl, {
                exchangeInfo: data
            });
            _this.fillMainContent(html);
            var userGames = data.user.games;
            _this.find(".item-refresh-btn").click(function(e, noTry) {
                var btn = $(this);
                var type = btn.data("type");
                var refreshBtn = _this.find(".item-refresh-btn-" + type);
                refreshBtn.hide();
                var amountMoney = _this.find(".amount-money-" + type);
                var amountWarning = _this.find(".amount-warning-" + type);
                var itemAmountLoading = _this.find(".amount-loading-" + type);
                if (type && ($.inArray(type, userGames) !== -1 || type === "SM")) {
                    itemAmountLoading.show();
                    amountMoney.hide();
                    amountWarning.hide();
                    _this.requestGet("/exchange/balance/" + type, null,
                    function(data) {
                        var info = data[type];
                        if (info === "刷新重试!") {
                            refreshBtn.show();
                        } else {
                            if ($.isNumeric(info)) {
                                var oneAmountMoney = $(amountMoney[0]);
                                if (!noTry && oneAmountMoney.data("isInitAmount")) {
                                    var oldMoney = oneAmountMoney.text();
                                    var newMoney = BaseJS.formatMoney(info);
                                    if (oldMoney === newMoney) {
                                        setTimeout(function() {
                                            if (!_this.isRemoved) {
                                                btn.triggerHandler("click", [true]);
                                            }
                                        },
                                        1000);
                                        return;
                                    }
                                }
                                amountMoney.text(BaseJS.formatMoney(info)).show();
                                oneAmountMoney.data("isInitAmount", true);
                            } else {
                                amountWarning.text(info).show();
                            }
                            itemAmountLoading.hide();
                            refreshBtn.hide();
                        }
                    },
                    {
                        noMask: true
                    });
                } else {
                    itemAmountLoading.hide();
                    amountWarning.hide();
                    refreshBtn.hide();
                    amountMoney.text("0.00").show();
                }
            });
            _this.find(".list-group-item").click(function() {
                var item = $(this);
                var itemRefreshBtn = item.find(".item-refresh-btn:visible");
                if (itemRefreshBtn.length > 0) {
                    itemRefreshBtn.triggerHandler("click");
                    return false;
                }
                if (item.find(".amount-warning:visible").length > 0) {
                    return false;
                }
            });
            _this.find(".main-container .from-item-refresh-btn").each(function() {
                var refreshBtn = $(this);
                var type = refreshBtn.data("type");
                if (type !== "SM") {
                    refreshBtn.triggerHandler("click");
                }
            });
            _this.getBodyMain().on("change", "[type='radio']",
            function() {
                if (this.checked) {
                    var unchecked = $(this).data("unchecked");
                    _this.find("#" + unchecked)[0].checked = false;
                }
            });
        });
        var exchangeAmountInput = _this.find(".exchange-amount");
        this.find(".main-refresh-btn").click(function() {
            MainJS.createModule("memberExchange", $.extend(this.initData, {
                exchangeAmount: exchangeAmountInput.val()
            }));
        });
        if (this.initData.exchangeAmount) {
            exchangeAmountInput.val(this.initData.exchangeAmount);
        }
        this.find(".exchange-btn").click(function() {
            var exchangeAmount = exchangeAmountInput.val();
            var exchangeFrom = _this.find("[name='exchangeFrom']:checked").val();
            var exchangeTo = _this.find("[name='exchangeTo']:checked").val();
            var fromAmount = _this.find(".from-amount-money-" + exchangeFrom);
            var exchangeFromAmount = Number($.trim(fromAmount.text()));
            if (!exchangeFrom) {
                showAlert("请选择转出方");
                return;
            }
            if (!exchangeTo) {
                showAlert("请选择转入方");
                return;
            }
            if (exchangeTo === exchangeFrom) {
                showAlert("转出方不能与转入方一样");
                return;
            }
            if (!exchangeAmount && !exchangeAmountInput[0].validationMessage) {
                showAlert("请填写转换金额",
                function() {
                    exchangeAmountInput.focus();
                });
                return;
            }
            if (/\./.test(exchangeAmount)) {
                showAlert("请填写整数金额",
                function() {
                    exchangeAmountInput.focus();
                });
                return;
            }
            if (!/^\d+$/.test(exchangeAmount) || exchangeAmount === "0") {
                showAlert("请填写正确的金额",
                function() {
                    exchangeAmountInput.focus();
                });
                return;
            }
            exchangeAmount = Number(exchangeAmount);
            if (fromAmount.is(":visible") && exchangeFromAmount < exchangeAmount) {
                showAlert("额度不足",
                function() {
                    exchangeAmountInput.focus();
                });
                return;
            }
            var refreshHandler = function() {
                _this.find(".item-refresh-btn-" + exchangeFrom).triggerHandler("click");
                _this.find(".item-refresh-btn-" + exchangeTo).triggerHandler("click");
            };
            _this.requestPost("/exchange/do", {
                amount: exchangeAmount,
                from: exchangeFrom,
                to: exchangeTo
            },
            null, {
                errorDialogHandler: function() {
                    refreshHandler();
                },
                successDialogHandler: function() {
                    refreshHandler();
                }
            });
        });
    }
});;
BaseJS.addModuleClass("MemberMessage", {
    init: function() {
        this.initData.type = this.initData.type || "message";
        this.renderBody("member_message", {
            type: this.initData.type
        });
    },
    actionIndex: function() {
        this.setPageTitle(this.initData.type === "sportNotice" ? "体育公告": "消息中心");
        this.initPullDownRefresh();
        var _this = this;
        var url = this.initData.type === "sportNotice" ? "/sport/notice": "/member/" + this.initData.type;
        this.requestGet(url, null,
        function(data) {
            var tpl = _this.getTpl("member_message", "list");
            var html = _this.renderTpl(tpl, {
                list: data.message
            });
            _this.fillMainContent(html);
        });
    }
});;
BaseJS.addModuleClass("MemberMoney", {
    init: function() {
        this.renderBody("member_money");
    },
    actionIndex: function() {
        this.setPageTitle("资金流水");
        var tpl = this.getTpl("member_money", "query");
        var html = this.renderTpl(tpl, {
            startTime: MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd"),
            endTime: MainJS.getTimeForServer((new Date()).getTime() + 3600 * 24 * 1000, "yyyy-MM-dd")
        });
        this.fillMainContent(html);
        this.find(".main-container .form-group").eq(2).show();
        var _this = this;
        this.find(".submit-btn").click(function() {
            var startTimeInput = _this.find("form [name='startTime']");
            var endTimeInput = _this.find("form [name='endTime']");
            var startTime = startTimeInput.val();
            var endTime = endTimeInput.val();
            if (!startTime) {
                showAlert("开始时间不能为空",
                function() {
                    startTimeInput.focus();
                });
                return;
            }
            if (!endTime) {
                showAlert("结束时间不能为空",
                function() {
                    endTimeInput.focus();
                });
                return;
            }
            MainJS.openModule("memberMoney", {
                action: 'list',
                startTime: startTime,
                endTime: endTime,
                type: _this.find("form [name='type']").val()
            });
        });
    },
    getBetList: function() {
        var url = "";
        if (this.betListPageInfo) {
            if (this.betListCurrentPage >= this.betListPageInfo.page) {
                return;
            }
        }
        if (this.betListPageInfo && this.betListCurrentPage > 0) {
            url = "/member/rdh/_page-" + (this.betListCurrentPage + 1) + "-" + this.betListPageInfo.total + "_";
        } else {
            url = "/member/rdh";
        }
        var _this = this;
        this.requestGet(url, {
            type: this.initData.type,
            startTime: this.initData.startTime,
            endTime: this.initData.endTime
        },
        function(data) {
            var tpl = _this.getTpl("member_money", "list");
            var html = _this.renderTpl(tpl, {
                list: data.rdh
            });
            _this.betListPageInfo = {
                page: data.page,
                total: data.total
            };
            if (_this.betListCurrentPage > 0) {
                _this.betListCurrentPage++;
            } else {
                _this.betListCurrentPage = 1;
            }
            if (_this.betListCurrentPage === 1 && data.rdh.length === 0) {
                html = '<div class="no-result">没有相关信息</div>';
                _this.find(".pull-up").hide();
            } else {
                if (_this.betListCurrentPage >= _this.betListPageInfo.page) {
                    html += '<div class="no-result">已没有更多</div>';
                    _this.find(".pull-up").hide();
                }
            }
            _this.appendMainContent(html);
            _this.countAmountList();
        });
    },
    countAmountList: function() {
        var totalBetAmount = 0;
        this.find(".list-group-item .item-amount").each(function() {
            totalBetAmount += Number($(this).data("amount"));
        });
        this.find(".total-list-amount").text(BaseJS.formatMoney(totalBetAmount));
    },
    actionList: function() {
        this.setPageTitle("资金流水");
        this.initPullDownRefresh();
        this.getBetList();
        var _this = this;
        this.getPullUpHandler = function() {
            if (!this.pullUpHandler) {
                this.pullUpHandler = function() {
                    _this.getBetList();
                };
            }
            return this.pullUpHandler;
        };
        this.getBodyMain().on("click", ".list-group-item",
        function() {
            $(this).find(".detail").toggle();
        });
    }
});;
BaseJS.addModuleClass("Sport", {
    init: function() {
        if (this.initData.stype === "fu") {
            this.initData.stype = "ft";
            this.initData.dtype = "future";
        } else if (this.initData.stype === "bbfu") {
            this.initData.stype = "bb";
            this.initData.dtype = "future";
        } else {
            this.initData.stype = this.initData.stype || "ft";
            this.initData.dtype = this.initData.dtype || (this.initData.type === "gq" ? "gq": "today");
        }
        this.initData.type = this.initData.type || "ds";
        this.renderBody("sport");
    },
    actionIndex: function() {
        this.setPageTitle(MainJS.getSportName(this.initData.stype) + " - " + MainJS.getPlayType(this.initData.stype, this.initData.type));
        this.initPullDownRefresh();
        var _this = this;
        this.getBodyMain().on("click", "li .item-area",
        function() {
            var itemArea = $(this);
            if (_this.initData.type === "zhgg") {
                var listArea = itemArea.data("listArea");
                if (listArea) {
                    listArea.toggle();
                    itemArea.toggleClass("item-area-active");
                } else {
                    itemArea.addClass("item-area-active");
                    _this.getDetailList(function(html, data) {
                        var listArea = $("<div class='match-item-area'>" + html + "</div>");
                        itemArea.after(listArea);
                        itemArea.data("listArea", listArea);
                        itemArea.find(".match-count").text(data.length);
                        _this.syncSelected();
                    },
                    itemArea.data("league"));
                }
            } else {
                MainJS.openModule("sport", {
                    action: "detail",
                    stype: _this.initData.stype,
                    type: _this.initData.type,
                    dtype: _this.initData.dtype,
                    league: itemArea.data("league")
                });
            }
        });
        this.getLeagueList();
        if (this.initData.type === "zhgg") {
            this.multiBetInit();
        }
    },
    getLeagueList: function() {
        var requestUrl = "";
        if (this.initData.dtype === "gq") {
            requestUrl = "/sport/" + this.initData.stype;
        } else {
            requestUrl = "/sport/" + this.initData.stype + "-" + this.initData.dtype;
        }
        requestUrl = requestUrl + "/" + this.initData.type;
        var _this = this;
        this.requestGet(requestUrl, null,
        function(data) {
            var tpl = _this.getTpl("sport", "leagueList");
            var html = _this.renderTpl(tpl, {
                list: data
            });
            _this.fillMainContent(html);
        });
    },
    actionDetail: function() {
        this.setPageTitle(this.initData.league + " - " + MainJS.getPlayType(this.initData.stype, this.initData.type));
        this.initPullDownRefresh();
        var _this = this;
        this.getDetailList(function(html) {
            _this.fillMainContent(html);
            _this.singleBetInit();
        });
    },
    getRealStype: function() {
        var stype = this.initData.stype;
        var dtype = this.initData.dtype;
        var realStype = "";
        if (stype === "ft") {
            if (dtype === "future") {
                realStype = "fu";
            } else {
                realStype = stype;
            }
        } else {
            if (dtype === "future") {
                realStype = stype + "fu";
            } else {
                realStype = stype;
            }
        }
        return realStype;
    },
    removeBetMatch: function(matchInfo, caller) {
        var realStype = this.getRealStype();
        var _this = this;
        this.requestGet("/sport/zhgg/" + (matchInfo.ftid || matchInfo.id || matchInfo.match_id), {
            cancel: 1,
            stype: realStype,
            type: this.initData.type,
            btype: matchInfo.btype
        },
        function(data) {
            _this.betData = data;
            _this.syncSelected();
            if (caller) {
                caller(data);
            }
        });
    },
    syncSelected: function() {
        var data = this.betData.zhgg ? this.betData.zhgg.data: null;
        var btns = this.find(".rate-btn");
        btns.each(function() {
            var btn = $(this);
            var matchId = btn.data("id");
            var btype = btn.data("btype");
            var selected = false;
            if (data) {
                $.each(data,
                function(k, v) {
                    if (v.match_id == matchId && v.btype == btype) {
                        selected = true;
                        return false;
                    }
                });
            }
            if (selected) {
                btn.addClass("selected-rate");
            } else {
                btn.removeClass("selected-rate");
            }
        });
        this.find(".selected-count").text(this.betData.zhgg ? this.betData.zhgg.count: 0);
        this.find(".total-rate").text(this.betData.zhgg ? this.betData.zhgg.rate: 0);
    },
    multiBetInit: function() {
        this.betData = {};
        var _this = this;
        this.getBodyMain().on("click", ".rate-btn",
        function() {
            var rateBtn = $(this);
            var btype = rateBtn.data("btype");
            var matchItem = rateBtn.closest(".match-item");
            var match = matchItem.data("match");
            var stype = _this.initData.stype;
            var matchId = stype === "ft" ? match.ftid: match.id;
            var realStype = _this.getRealStype();
            if (rateBtn.hasClass("selected-rate")) {
                _this.removeBetMatch(match);
            } else {
                _this.requestGet("/sport/zhgg/" + matchId, {
                    stype: realStype,
                    type: _this.initData.type,
                    btype: btype
                },
                function(data) {
                    _this.betData = data;
                    _this.syncSelected();
                });
            }
        });
        this.find(".bet-confirm-btn,.selected-info").click(function() {
            if (Number($.trim(_this.find(".selected-count").text())) > 0) {
                _this.requestGet("/sport/zhgg", {
                    stype: _this.getRealStype(),
                    type: "zhgg"
                },
                function(data) {
                    var betTpl = _this.getTpl("sport", "betSelected");
                    MainJS.showDialog({
                        title: _this.betData.title,
                        content: _this.renderTpl(betTpl, {
                            matchData: data
                        }),
                        onInit: function(dialog) {
                            _this.initBetDialog(dialog, data);
                        }
                    });
                });
            } else {
                if ($(this).hasClass("bet-confirm-btn")) {
                    showAlert("请选择串关项目");
                }
            }
        });
        this.requestGet("/sport/zhgg", {
            stype: this.getRealStype(),
            type: "zhgg"
        },
        function(data) {
            _this.betData = data;
            _this.syncSelected();
        });
    },
    singleBetInit: function() {
        var _this = this;
        this.find(".rate-btn").click(function() {
            var rateBtn = $(this);
            var btype = rateBtn.data("btype");
            var matchItem = rateBtn.closest(".match-item");
            var match = matchItem.data("match");
            var stype = _this.initData.stype;
            var matchId = stype === "ft" ? match.ftid: match.id;
            var realStype = _this.getRealStype();
            _this.requestGet("/sport/order/" + matchId, {
                stype: realStype,
                type: _this.initData.type,
                btype: btype
            },
            function(matchData) {
                var betTpl = _this.getTpl("sport", "bet");
                MainJS.showDialog({
                    title: matchData.league + " " + matchData.title,
                    content: _this.renderTpl(betTpl, {
                        matchData: matchData
                    }),
                    onInit: function(dialog) {
                        _this.initBetDialog(dialog, matchData);
                    }
                });
            });
        });
    },
    getDetailList: function(caller, league) {
        var _this = this;
        var requestUrl = "";
        if (this.initData.dtype === "gq") {
            requestUrl = "/sport/" + this.initData.stype;
        } else {
            requestUrl = "/sport/" + this.initData.stype + "-" + this.initData.dtype;
        }
        requestUrl = requestUrl + "/" + this.initData.type;
        this.requestGet(requestUrl, {
            league: this.initData.league || league
        },
        function(data) {
            var tpl = _this.getTpl("sport", "detailList");
            var html = _this.renderTpl(tpl, {
                list: data
            });
            caller(html, data || []);
        });
    },
    initBetDialog: function(dialog, matchData) {
        var betMoneyInput = dialog.find(".bet_money");
        var _this = this;
        dialog.find(".do-bet-btn").click(function() {
            if (matchData.zhgg && matchData.zhgg.count < matchData.zhgg.max_sg_num) {
                showAlert("串关数目不能少于" + matchData.zhgg.max_sg_num + "个");
                return;
            }
            if (matchData.zhgg && matchData.zhgg.count > 10) {
                showAlert("串关数目不能多于10个");
                return;
            }
            var betMoney = $.trim(betMoneyInput.val());
            if (!betMoney && !betMoneyInput[0].validationMessage) {
                showAlert("请填写下注金额",
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            if (/\./.test(betMoney)) {
                showAlert("请填写整数金额",
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            if (!/^\d+$/.test(betMoney)) {
                showAlert("请填写正确的金额",
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            betMoney = Number(betMoney);
            if (betMoney > Number(matchData.money)) {
                showAlert("您的余额不足",
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            if (betMoney < Number(matchData.low_limit)) {
                showAlert("投注金额不能低于" + matchData.low_limit,
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            if (betMoney > Number(matchData.hight_limit)) {
                showAlert("投注金额不能高于" + matchData.hight_limit,
                function() {
                    betMoneyInput.focus();
                });
                return;
            }
            showConfirm("投注金额：" + betMoney + "\n可赢金额：" + dialog.find(".calc-win").text() + "\n确定要投注吗？",
            function() {
                if (matchData.zhgg) {
                    _this.requestPost("/sport/dozhgg", {
                        stype: matchData.stype,
                        type: matchData.type,
                        gold: betMoney
                    });
                } else {
                    _this.requestPost("/sport/doorder", {
                        match_id: matchData.match_id,
                        stype: matchData.stype,
                        type: matchData.type,
                        btype: matchData.btype,
                        gold: betMoney
                    },
                    null, {
                        successDialogHandler: function() {
                            dialog.remove();
                        }
                    });
                }
            });
        });
        dialog.find(".suggest .btn").click(function() {
            betMoneyInput.val($(this).data("money"));
            betMoneyInput.change();
        });
        betMoneyInput.bind("change input",
        function() {
            var rate = 0;
            if (matchData.zhgg) {
                rate = Number(matchData.zhgg.rate || 0);
            } else {
                rate = Number(matchData.rate || 0);
            }
            var money = Number(this.value);
            var calcResult = 0;
            if (matchData.minus > 0) {
                calcResult = money * rate - money;
            } else {
                calcResult = money * rate;
            }
            calcResult = calcResult > 0 ? calcResult: 0;
            dialog.find(".calc-win").text(BaseJS.formatMoney(calcResult));
        });
        var refreshBtn = dialog.find(".refresh-btn");
        if (refreshBtn.length > 0) {
            var timeCount = 10;
            var timeCountArea = dialog.find(".time-count");
            var timer = null;
            refreshBtn.click(function() {
                _this.requestGet("/sport/order/" + matchData.match_id, {
                    stype: matchData.stype,
                    type: matchData.type,
                    btype: matchData.btype
                },
                function(newMatchData) {
                    if (!newMatchData) {
                        return;
                    }
                    matchData = newMatchData;
                    timeCount = 10;
                    timeCountArea.text(timeCount);
                    dialog.find(".rate-info").text(matchData.rate);
                    betMoneyInput.change();
                },
                {
                    errorDialogHandler: function() {
                        dialog.remove();
                    },
                    errorHandler: function() {
                        if (timer) {
                            clearInterval(timer);
                            timer = null;
                        }
                    }
                });
            });
            timer = setInterval(function() {
                if (timeCount <= 0) {
                    timeCount = 10;
                    refreshBtn.click();
                } else {
                    timeCount--;
                }
                timeCountArea.text(timeCount);
            },
            1000);
            dialog.on("remove",
            function() {
                if (timer) {
                    clearInterval(timer);
                    timer = null;
                }
            });
        }
        var betTotalInfo = dialog.find(".bet-total-info");
        var syncBetTotalInfo = function() {
            if (betTotalInfo.length > 0) {
                betTotalInfo.html('<span class="txt-important">' + (matchData.zhgg ? matchData.zhgg.count: 0) + '</span>串1 @<span class="info-warning">' + (matchData.zhgg ? matchData.zhgg.rate: 0) + '</span>');
            }
        };
        syncBetTotalInfo();
        dialog.find(".match-remove-btn").click(function() {
            var removeBtn = $(this);
            var match = removeBtn.data("match");
            _this.removeBetMatch(match,
            function(data) {
                matchData = data;
                removeBtn.closest(".match-item").remove();
                if (dialog.find(".match-item").length === 0) {
                    dialog.find(".list-group").after('<div class="no-result">无相关信息</div>');
                }
                syncBetTotalInfo();
                dialog.syncSize();
            });
        });
    }
});;
BaseJS.addModuleClass("SportResult", {
    init: function() {
        this.renderBody("sport_result");
    },
    actionIndex: function() {
        this.initData.stype = this.initData.stype || "ft";
        var stypes = this.initData.stype;
        this.setPageTitle(this.initData.stype === "ft" ? "足球赛果": "篮球赛果");
        this.initPullDownRefresh();
        this.initData.date = MainJS.getTimeForServer((new Date(this.initData.date)).getTime(), "yyyy-MM-dd") || MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd");
        var today = MainJS.getTimeForServer((new Date()).getTime(), "yyyy-MM-dd");
        var yesday = MainJS.getTimeForServer((new Date(this.initData.date)).getTime() - 3600 * 24 * 1000, "yyyy-MM-dd");
        var nextday = MainJS.getTimeForServer((new Date(this.initData.date)).getTime() + 3600 * 24 * 1000, "yyyy-MM-dd");
        this.find(".top-menu-result .fontday").click(function() {
            MainJS.openModule("sportResult", {
                stype: stypes,
                date: yesday
            });
        });
        if (this.initData.date == today) {
            this.find(".top-menu-result .nextday").hide();
        } else {
            this.find(".top-menu-result .nextday").click(function() {
                MainJS.openModule("sportResult", {
                    stype: stypes,
                    date: nextday
                });
            });
        }
        var _this = this;
        var requestUrl = "/sport/sg/" + this.initData.stype;
        this.requestGet(requestUrl, {
            date: this.initData.date
        },
        function(data) {
            var tpl = _this.getTpl("sport_result", "resultList");
            var html = _this.renderTpl(tpl, {
                list: data
            });
            _this.fillMainContent(html);
        });
    }
});;
BaseJS.classes.MainController = function(cfg) {
    BaseJS.classes.MainController.superClass.constructor.apply(this, arguments);
    this.cfg = cfg;
};
BaseJS.classExtend(BaseJS.classes.MainController, BaseJS.classes.BaseController, {
    init: function() {
        this.adaptSystem();
        var _this = this;
        this.getTemplateAll(function() {
            _this.doInit();
        });
    },
    doInit: function() {
        this.triggerHandler("beforeInit");
        if (this.sysSetting.bodyClass) {
            $(document.body).addClass(this.sysSetting.bodyClass);
        }
        if (!this.isApp) {
            this.initMenu();
        }
        this.bindNavigate();
        this.setLoginState(this.cfg.data.mid ? true: false);
        if (this.cfg.maintence) {
            this.openModule("common", {
                action: "message",
                info: this.cfg.maintence
            });
            return;
        }
        if (!this.getLocationHash()) {
            if (this.isApp) {
                if (this.cfg.data.QRCode) {
                    this.openModule("common", {
                        action: "download"
                    });
                }
            } else {
                this.goHome();
            }
        }
    },
    checkLogin: function() {
        return $.cookie("BASEJS_IS_MEMBER_LOGIN") === "1" ? true: false;
    },
    setLoginState: function(isLogin) {
        $.cookie("BASEJS_IS_MEMBER_LOGIN", isLogin ? "1": "0", {
            path: "/"
        });
        if (this.layoutCfg.bodyBottom) {
            if (!this.logoutMenuItem) {
                this.logoutMenuItem = this.layoutCfg.bodyBottom.find(".menu-logout-btn");
                this.logoutMenuPrev = this.logoutMenuItem.prev();
                if (this.logoutMenuPrev.length === 0) {
                    this.logoutMenuParent = this.logoutMenuItem.parent();
                }
                this.logoutMenuItem.remove();
            }
            if (isLogin) {
                if (this.logoutMenuParent) {
                    this.logoutMenuParent.prepend(this.logoutMenuItem);
                } else {
                    this.logoutMenuPrev.after(this.logoutMenuItem);
                }
            } else {
                this.logoutMenuItem.remove();
            }
        }
    },
    goBack: function() {
        if (this.clickMenuItem) {
            var clickMenuItem = this.clickMenuItem;
            this.clickMenuItem = null;
            var menuItem = $(clickMenuItem).data("item");
            if (this.checkOpenWin(menuItem)) {
                this.goBack();
            }
            this.checkClick(clickMenuItem);
        } else if (this.navigateCount <= 1) {
            this.goHome();
        } else {
            window.history.back();
        }
    },
    initMenu: function() {
        var moduleInfo = this.parserModuleUrl();
        if (moduleInfo && moduleInfo.moduleName === "common" && moduleInfo.moduleCfg.action === "exchange") {
            return;
        }
        if (this.cfg.data.config && !this.isApp && this.cfg.data.config.mainMenu && !this.isSubSystem) {
            if (!this.layoutCfg.bodyBottom) {
                this.layoutCfg.bodyBottom = $('<div class="layout-bottom"></div>');
                this.layoutCfg.bodyMain.after(this.layoutCfg.bodyBottom);
            }
            var menuTpl = this.getTpl("common", "mainMenu");
            var mainMenu = MainJS.cfg.data.config.mainMenu;
            var lastMenuItem = mainMenu[mainMenu.length - 1];
            if (lastMenuItem.sub) {
                lastMenuItem.sub.push({
                    name: "安全退出",
                    class: "menu-logout-btn",
                    onclick: "MainJS.logout();"
                });
            }
            var menuHtml = this.renderTpl(menuTpl, {
                mainMenu: mainMenu
            });
            this.layoutCfg.bodyBottom.append(menuHtml);
            this.clickMenuItem = null;
            var _this = this;
            this.layoutCfg.bodyBottom.find(".dropup").width((100 / mainMenu.length) + "%");
            if (BaseJS.isWebKit) {
                this.layoutCfg.bodyBottom.find(".dropup >a").attr("tabindex", "1").css("outline-style", "none");
            }
            this.layoutCfg.bodyBottom.find(".dropdown-menu").each(function(k, v) {
                var container = $(v);
                var content = container.find(">*");
                content.remove();
                container.append('<li><ul style="list-style:none;padding:0;margin:0;"></ul></li>');
                container.find("ul").append(content);
                container.data("scrollbar", BaseJS.createScrollbar({
                    target: container,
                    isAutoHeight: true
                }));
            });
            this.layoutCfg.bodyBottom.find(".main-menu-area a").click(function(e) {
                _this.checkClick(this, e);
            });
            this.syncSize();
        }
    },
    cacheTpls: function(tplList) {
        if (tplList) {
            var _this = this;
            $.each(tplList,
            function(k, v) {
                _this.getTplData(v);
            });
        }
    },
    getTemplateAll: function(caller) {
        var _this = this;
        var getTplAll = function(data) {
            $.each(data,
            function(k, v) {
                _this.tplCache[k] = _this.getTplInfo(v);
            });
            if (caller) {
                caller();
            }
        };
        if (window.BASEJS_TPL_ALL) {
            getTplAll(BASEJS_TPL_ALL);
        } else {
            this.requestGet("/app_static/template_all.php", null,
            function(data) {
                getTplAll(data);
            });
        }
    },
    getTplInfo: function(tplStr) {
        var result = null;
        var exp = /<!--tplStart:(\w+)-->([\s\S]*?)<!--tplEnd-->/g;
        var tpls = {};
        while ((result = exp.exec(tplStr)) !== null) {
            tpls[result[1]] = result[2];
        }
        return tpls;
    },
    getTplData: function(tplId) {
        if (this.tplCache[tplId]) {
            return this.tplCache[tplId];
        }
        var tplStr = "";
        this.requestGet("/app_static/js/templates/" + tplId + ".tpl", null,
        function(data) {
            tplStr = data;
        },
        {
            async: false,
            dataType: "html"
        });
        this.tplCache[tplId] = this.getTplInfo(tplStr);
        return this.tplCache[tplId];
    },
    getTimeForServer: function(dateTime, format) {
        if ($.isNumeric(dateTime)) {
            dateTime = new Date(dateTime);
        }
        dateTime = dateTime || new Date();
        var clientOffsetHour = (dateTime.getTimezoneOffset() / 60) * -1;
        var serverOffsetHour = this.cfg.serverOffsetHour;
        var diffTime = (clientOffsetHour - serverOffsetHour) * 3600000;
        var serverTime = dateTime.getTime() - diffTime;
        return BaseJS.formatDate(serverTime, format);
    },
    getTypeList: function(stype) {
        if (stype === "ft") {
            var list = [{
                name: "单式",
                id: "ds"
            },
            {
                name: "波胆",
                id: "bd"
            },
            {
                name: "入球数",
                id: "zrq"
            },
            {
                name: "半全场",
                id: "bqs"
            },
            {
                name: "滚球",
                id: "gq"
            },
            {
                name: "综合过关",
                id: "zhgg"
            }];
        } else {
            var list = [{
                name: "单式",
                id: "ds"
            },
            {
                name: "滚球",
                id: "gq"
            },
            {
                name: "综合过关",
                id: "zhgg"
            }];
        }
        return list;
    },
    getSportList: function() {
        var list = [{
            name: "足球",
            id: "ft"
        },
        {
            name: "篮球",
            id: "bb"
        },
        {
            name: "棒球",
            id: "ba",
            disabled: true
        },
        {
            name: "网球",
            id: "te",
            disabled: true
        },
        {
            name: "排球",
            id: "vo",
            disabled: true
        },
        {
            name: "其他",
            id: "ot",
            disabled: true
        }];
        return list;
    },
    getSportName: function(id) {
        var list = this.getSportList();
        var sportName = "";
        $.each(list,
        function(k, v) {
            if (id === v.id) {
                sportName = v.name;
                return false;
            }
        });
        return sportName;
    },
    getPlayType: function(stype, id) {
        var list = this.getTypeList(stype);
        var playType = "";
        $.each(list,
        function(k, v) {
            if (id === v.id) {
                playType = v.name;
                return false;
            }
        });
        return playType;
    },
    postMessage: function(data) {
        top.postMessage(data, "*");
    },
    showLogout: function(message) {
        this.setLoginState(false);
        if (this.isApp) {
            this.postMessage({
                ptl: "logout",
                message: message || ""
            });
        } else {
            var _this = this;
            showAlert(message || "未知原因登出",
            function() {
                _this.login();
            });
        }
    },
    setWindowShow: function(cfg) {
        if (this.sysSetting.isPostMessageSetWindow) {
            this.postMessage({
                ptl: "window",
                message: {
                    showLogo: cfg.showLogo,
                    orientation: cfg.orientation
                }
            });
            this.syncSize();
        }
    },
    openLink: function(url) {
        this.openModule("common", {
            action: "openLink",
            url: url
        });
    },
    openInApp: function(url, title, cfg) {
        cfg = cfg || {};
        this.postMessage({
            ptl: "window",
            message: {
                showLogo: cfg.showLogo || "0",
                mode: "inappbrowser",
                url: url,
                title: title || "",
                orientation: cfg.orientation || "s",
                history: "1"
            }
        });
    },
    openApp: function(url, title, cfg) {
        cfg = cfg || {};
        this.postMessage({
            ptl: "window",
            message: {
                showLogo: cfg.showLogo || "0",
                mode: "openApp",
                url: url,
                title: title || "",
                orientation: cfg.orientation || "s",
                history: "1"
            }
        });
    },
    openWin: function(url, title, cfg) {
        title = title || "新窗口";
        cfg = cfg || {};
        if (this.sysSetting.isPostMessageSetWindow) {
            if (!/^https?\:\/\//.test(url)) {
                var baseUrl = window.location.protocol + "//" + window.location.host;
                if (/^\//.test(url)) {
                    url = baseUrl + url;
                } else if (/^#/.test(url)) {
                    url = baseUrl + window.location.pathname + url;
                } else {
                    var pathInfo = window.location.pathname.split("/");
                    pathInfo[pathInfo.length - 1] = url;
                    url = baseUrl + pathInfo.join("/");
                }
            }
            this.postMessage({
                ptl: "window",
                message: {
                    showLogo: cfg.showLogo || "0",
                    mode: cfg.mode || "sub",
                    url: url,
                    title: title || "",
                    orientation: cfg.orientation || "s",
                    history: "1"
                }
            });
        } else {
            window.open(url);
        }
    },
    logout: function() {
        var _this = this;
        this.requestGet("/index/logout", null,
        function() {
            _this.setLoginState(false);
            _this.goHome(true);
        });
    },
    login: function() {
        this.openModule("member", {
            action: "login"
        });
    },
    checkOpenWin: function(menuItem) {
        if (!menuItem.url) {
            return false;
        }
        if ((!/^#/.test(menuItem.url) && (BaseJS.isMac || BaseJS.isSafari || menuItem.mode === "sub")) || menuItem.mode === "inappbrowser" || menuItem.mode === "insidebrowser") {
            return true;
        } else {
            return false;
        }
    },
    checkClick: function(element, e, noCheckMoney, isReplace) {
        var obj = $(element);
        var menuItem = obj.data("item");
        if (!menuItem) {
            return;
        }
        var _this = this;
        if (!this.checkLogin() && menuItem.login == 1) {
            this.clickMenuItem = element;
            this.showLogout("请先登录",
            function() {
                _this.login();
            });
            return;
        }
        if (!noCheckMoney) {
            if (menuItem.target) {
                if (this.checkOpenWin(menuItem) && !this.isApp) {
                    MainJS.openModule("common", {
                        action: "exchange",
                        target: menuItem.target,
                        url: menuItem.url
                    },
                    true);
                } else {
                    this.requestGet("/exchange/balance/" + menuItem.target, null,
                    function(data) {
                        var info = data[menuItem.target];
                        if (info >= 1 || info === "刷新重试!") {
                            _this.checkClick(element, e, true, isReplace);
                        } else {
                            _this.showExchangeDialog(menuItem.target,
                            function() {
                                _this.checkClick(element, e, true, isReplace);
                            });
                        }
                    },
                    {
                        async: this.checkOpenWin(menuItem) && !this.isApp ? false: true,
                        error: function() {
                            _this.checkClick(element, e, true, isReplace);
                        }
                    });
                }
                return;
            }
        }
        if (!/^#/.test(menuItem.url) && menuItem.mode === "main" && this.isApp) {
            this.setWindowShow(menuItem);
            this.openLink(menuItem.url);
            return;
        }
        if (this.checkOpenWin(menuItem)) {
            this.openWin(menuItem.url, menuItem.name || $.trim(obj.text()), menuItem);
        } else {
            this.setWindowShow(menuItem);
            if (/^#/.test(menuItem.url)) {
                if (isReplace) {
                    window.location.replace(menuItem.url);
                } else {
                    window.location = menuItem.url;
                }
            } else {
                if (menuItem.url) {
                    if (this.isApp) {
                        if (isReplace) {
                            window.location.replace(menuItem.url);
                        } else {
                            window.location = menuItem.url;
                        }
                    } else {
                        if (BaseJS.isMac || BaseJS.isSafari) {
                            window.open(menuItem.url);
                        } else {
                            this.openLink(menuItem.url);
                        }
                    }
                }
            }
        }
    },
    getHomeIcon: function(menuId) {
        return this.sysSetting.homeIcon[menuId] || ("/app_static/images/menu_btns/" + menuId + ".png");
    },
    getSecondIcon: function(menuId) {
        return this.sysSetting.secondIcon[menuId] || ("/app_static/images/icons/" + menuId + ".png");
    },
    getMainIconClass: function(menuId) {
        return this.sysSetting.mainIconClass[menuId] || "";
    },
    showExchangeDialog: function(targetId, caller) {
        var tpl = this.getTpl("common", "moneyExchange");
        var _this = this;
        var dialog = this.showDialog({
            content: this.renderTpl(tpl),
            containerClass: "exchange-dialog-main",
            onInit: function(dialog) {
                var tpl = _this.getTpl("common", "exchangeToolbar");
                dialog.getDialogBody().after(_this.renderTpl(tpl));
                var selectedAmount = dialog.find(".selected-amount");
                var selectedName = dialog.find(".selected-name");
                var exchangeAmountInput = dialog.find(".exchange-amount");
                var initData = null;
                var selectedFromAmount = 0;
                var selectedFrom = "SM";
                _this.requestGet("/exchange", null,
                function(data) {
                    initData = data;
                    selectedFromAmount = data.user.money;
                    selectedAmount.text(BaseJS.formatMoney(data.user.money)).show();
                    var targetName = "";
                    $.each(data.option,
                    function(k, v) {
                        if (v.key === targetId) {
                            targetName = v.name;
                            return false;
                        }
                    });
                    dialog.setTitle("[" + targetName + "]余额不足");
                    exchangeAmountInput.val(Math.floor(Number(data.user.money)));
                });
                var selectBtn = dialog.find(".select-btn");
                selectBtn.click(function() {
                    var selectList = selectBtn.data("selectList");
                    if (!selectList) {
                        var tpl = _this.getTpl("common", "exchangeSelectList");
                        selectList = $(_this.renderTpl(tpl, initData));
                        selectBtn.after(selectList);
                        selectBtn.data("selectList", selectList);
                        selectList.find(".item-refresh-btn").click(function() {
                            var refreshBtn = $(this);
                            var type = $(this).data("type");
                            refreshBtn.hide();
                            var amountMoney = selectList.find(".amount-money-" + type);
                            var amountWarning = selectList.find(".amount-warning-" + type);
                            var itemAmountLoading = selectList.find(".amount-loading-" + type);
                            if (type && ($.inArray(type, initData.user.games) !== -1 || type === "SM")) {
                                itemAmountLoading.show();
                                amountMoney.hide();
                                amountWarning.hide();
                                _this.requestGet("/exchange/balance/" + type, null,
                                function(data) {
                                    var info = data[type];
                                    itemAmountLoading.hide();
                                    if (info === "刷新重试!") {
                                        refreshBtn.show();
                                    } else {
                                        if ($.isNumeric(info)) {
                                            amountMoney.text(BaseJS.formatMoney(info)).show();
                                        } else {
                                            amountWarning.text(info).show();
                                        }
                                        refreshBtn.hide();
                                    }
                                },
                                {
                                    noMask: true
                                });
                            } else {
                                itemAmountLoading.hide();
                                amountWarning.hide();
                                refreshBtn.hide();
                                amountMoney.text("0.00").show();
                            }
                        });
                        selectList.find(".item-refresh-btn").each(function() {
                            var refreshBtn = $(this);
                            var type = refreshBtn.data("type");
                            if (type !== "SM") {
                                refreshBtn.triggerHandler("click");
                            }
                        });
                        selectList.find(">li").click(function() {
                            var item = $(this);
                            var amountMoneyItem = item.find(".amount-money");
                            if (amountMoneyItem.is(":hidden")) {
                                return;
                            }
                            selectedFrom = item.find(".item-refresh-btn").data("type");
                            var selectedFromAmountTxt = amountMoneyItem.text();
                            selectedName.text(item.find(".item-name").text());
                            selectedAmount.text(selectedFromAmountTxt);
                            selectedFromAmount = Number(selectedFromAmountTxt);
                            selectList.hide();
                            exchangeAmountInput.val(Math.floor(selectedFromAmount));
                        });
                    }
                    selectList.toggle();
                });
                dialog.find(".exchange-btn").click(function() {
                    var exchangeAmount = exchangeAmountInput.val();
                    var exchangeFrom = selectedFrom;
                    var exchangeTo = targetId;
                    var exchangeFromAmount = selectedFromAmount;
                    if (!exchangeFrom) {
                        showAlert("请选择转出方");
                        return;
                    }
                    if (!exchangeTo) {
                        showAlert("请选择转入方");
                        return;
                    }
                    if (exchangeTo === exchangeFrom) {
                        showAlert("转出方不能与转入方一样");
                        return;
                    }
                    if (!exchangeAmount && !exchangeAmountInput[0].validationMessage) {
                        showAlert("请填写转换金额",
                        function() {
                            exchangeAmountInput.focus();
                        });
                        return;
                    }
                    if (/\./.test(exchangeAmount)) {
                        showAlert("请填写整数金额",
                        function() {
                            exchangeAmountInput.focus();
                        });
                        return;
                    }
                    if (!/^\d+$/.test(exchangeAmount) || exchangeAmount === "0") {
                        showAlert("请填写正确的金额",
                        function() {
                            exchangeAmountInput.focus();
                        });
                        return;
                    }
                    exchangeAmount = Number(exchangeAmount);
                    if (exchangeFromAmount < exchangeAmount) {
                        showAlert("额度不足",
                        function() {
                            exchangeAmountInput.focus();
                        });
                        return;
                    }
                    _this.requestPost("/exchange/do", {
                        amount: exchangeAmount,
                        from: exchangeFrom,
                        to: exchangeTo
                    },
                    null, {
                        errorDialogHandler: function() {
                            dialog.find(".item-refresh-btn-" + exchangeFrom).triggerHandler("click");
                        },
                        successDialogHandler: function() {
                            dialog.remove();
                            if (caller) {
                                caller();
                            }
                        }
                    });
                });
                dialog.find(".skip-btn").click(function() {
                    dialog.remove();
                    if (caller) {
                        caller();
                    }
                });
            }
        });
        return dialog;
    },
    initSystemInfo: function() {
        this.isApp = this.cfg.data.platform === "wap" ? true: false;
        this.isTG = this.cfg.data.system === "TG" ? true: false;
        this.isTBK = this.cfg.data.system === "TBK" ? true: false;
        this.isTBKApp = this.isApp && this.isTBK ? true: false;
        this.isTBKWeb = !this.isApp && this.isTBK ? true: false;
        this.isTGApp = this.isApp && this.isTG ? true: false;
        this.isTGWeb = !this.isApp && this.isTG ? true: false;
        if (this.isTBK) {
            this.system = "TBK";
        }
        if (this.isTG) {
            this.system = "TG";
        }
        this.isSubSystem = false;
        try {
            if (window.parent.MainJS && window.parent.MainJS !== this) {
                this.isSubSystem = true;
            }
        } catch(e) {}
    },
    goHome: function(isForce) {
        if (isForce && window.location.hash === this.sysSetting.homeUrl && this.activeModule) {
            this.activeModule.refreshModule();
        } else {
            window.location = this.sysSetting.homeUrl;
        }
    },
    adaptSystem: function() {
        this.initSystemInfo();
        if (this.isApp) {
            var _this = this;
            $(window).bind("beforeunload",
            function() {
                _this.isUnloading = true;
                _this.showMask();
            });
            this.on("beforeInit",
            function() {
                if (_this.cfg.data.sid && _this.cfg.data.mid) {
                    _this.postMessage({
                        ptl: "member",
                        message: {
                            login: "1",
                            sid: _this.cfg.data.sid,
                            mid: _this.cfg.data.mid
                        }
                    });
                } else {
                    _this.postMessage({
                        ptl: "member",
                        message: {
                            login: "0",
                            sid: "",
                            mid: ""
                        }
                    });
                }
            });
        }
        this.hideModuleActions = ["common/menuLink", "common/openInApp"];
        if (this.system) {
            if (this["adapt" + this.system]) {
                this["adapt" + this.system]();
            }
        } else {
            this.sysSetting = {};
        }
    },
    adaptTBK: function() {
        this.initSysTBK();
    },
    adaptTG: function() {
        this.initSysTG();
    },
    initSysTG: function() {
        var moduleInfo = this.parserModuleUrl();
        if (moduleInfo && moduleInfo.moduleName === "common" && moduleInfo.moduleCfg.action === "home" && moduleInfo.moduleCfg.version) {
            $.cookie("BASEJS_APP_VERSION", moduleInfo.moduleCfg.version, {
                path: "/"
            });
        }
        var appVersion = $.cookie("BASEJS_APP_VERSION");
        var isNewApp = (appVersion == "2") ? true: false;
        this.sysSetting = {
            homeUrl: this.isApp ? "#module/member": "#module/common/action/home",
            bodyClass: "tg_style",
            isEnableCdn: this.cfg.cdnUrl ? true: false,
            orderMenuItems: [{
                id: "ty",
                name: "体育",
                items: [{
                    name: "系统体育",
                    id: "st"
                },
                {
                    name: "三昇体育",
                    id: "ts"
                },
                {
                    name: "沙巴体育",
                    id: "sp"
                }]
            },
            {
                id: "sx",
                name: "视讯",
                items: [{
                    name: "AG国际馆",
                    id: "ag"
                },
                {
                    name: "BBIN馆",
                    id: "bb"
                },
                {
                    name: "HG名人馆",
                    id: "ho"
                },
                {
                    name: "OG东方馆",
                    id: "og"
                },
                {
                    name: "AB亚洲馆",
                    id: "ab"
                },
                {
                    name: "DS太阳城",
                    id: "ds"
                }]
            },
            {
                id: "dz",
                name: "电子",
                items: [{
                    name: "MG电子",
                    id: "mg"
                },
                {
                    name: "PT电子",
                    id: "pt"
                },
                {
                    name: "HB电子",
                    id: "hb"
                },
                {
                    name: "YG电子",
                    id: "yg"
                },
                {
                    name: "BB电子",
                    id: "bg"
                },
                {
                    name: "MW电子",
                    id: "mw"
                }]
            },
            {
                id: "cp",
                name: "彩票",
                items: [{
                    name: "皇家彩票",
                    id: "dc"
                },
                {
                    name: "VR彩票",
                    id: "vr"
                }]
            },
            {
                id: "qp",
                name: "棋牌",
                items: [{
                    name: "VG斗地主",
                    id: "vg"
                },
                {
                    name: "AG捕鱼王",
                    id: "by"
                }]
            }],
            homeIcon: {
                sport: "/app_static/images/menu_btns/tg_hg_sports.png",
                jl: "/app_static/images/menu_btns/jl.png",
                jc: "/app_static/images/menu_btns/jl.png",
                hb: "/app_static/images/menu_btns/hb.png",
                yg: "/app_static/images/menu_btns/yg.png",
                ag: "/app_static/images/menu_btns/ag_ls.png",
                webchat: "/app_static/images/menu_btns/ocs.png",
                moreMenu: "/app_static/images/menu_btns/more.png",
                mg: "/app_static/images/menu_btns/mg.png",
                sp: "/app_static/images/menu_btns/sp.png",
                ho: "/app_static/images/menu_btns/ho.png",
                ab: "/app_static/images/menu_btns/ab.png",
                ds: "/app_static/images/menu_btns/ds.png",
                dc: "/app_static/images/menu_btns/dc.png",
                lo: "/app_static/images/menu_btns/dc.png",
                le: "/app_static/images/menu_btns/dc.png",
                bb: "/app_static/images/menu_btns/bbin.png",
                bg: "/app_static/images/menu_btns/bbin.png",
                pt: "/app_static/images/menu_btns/pt.png",
                ug: "/app_static/images/menu_btns/ug.png"
            },
            secondIcon: {
                sport: "/app_static/images/icons/hgty.png",
                sp: "/app_static/images/icons/sb.png",
                ts: "/app_static/images/icons/ss.png",
                jl: "/app_static/images/icons/jl.png",
                jc: "/app_static/images/icons/jl.png",
                ag: "/app_static/images/icons/ag.png",
                hb: "/app_static/images/icons/hb.png",
                mg: "/app_static/images/icons/mg.png",
                ho: "/app_static/images/icons/hg.png",
                yg: "/app_static/images/icons/yg.png",
                webchat: "/app_static/images/icons/zx.png",
                ab: "/app_static/images/icons/ab.png",
                ds: "/app_static/images/icons/ds.png",
                dc: "/app_static/images/icons/dc.png",
                lo: "/app_static/images/icons/dc.png",
                le: "/app_static/images/icons/dc.png",
                bb: "/app_static/images/icons/bbin.png",
                bg: "/app_static/images/icons/bbin.png",
                pt: "/app_static/images/icons/pt.png",
                ug: "/app_static/images/icons/ug.png"
            },
            mainIconClass: {
                tiyu: "iconfont icon-tiyu",
                caipiao: "iconfont icon-caipiao",
                shixun: "iconfont icon-shixun",
                dianzi: "iconfont icon-dianziyouxi",
                wo: "iconfont icon-huiyuan",
                home: "iconfont icon-shouye",
                message: "glyphicon glyphicon-volume-up",
                money: "glyphicon glyphicon-credit-card",
                info: "glyphicon glyphicon-user",
                exchange: "glyphicon glyphicon-transfer",
                all: "glyphicon glyphicon-knight"
            },
            isPostMessageSetWindow: this.isApp && isNewApp,
            modules: {
                game: isNewApp ? {
                    downloadMethod: this.isApp ? "openInApp": "",
                    openAppMethod: this.isApp ? "openApp": ""
                }: {
                    isOpenLocation: true
                },
                common: {
                    isShowHomeHead: !this.isApp,
                    homeNoticeIconClass: "fa fa-volume-up notice-icon",
                    defaultLunbo: ["/app_static/images/carousel/tg_0.jpg", "/app_static/images/carousel/tg_1.jpg", "/app_static/images/carousel/tg_2.jpg"],
                    defaultLogo: "/app_static/images/tg_logo.png",
                    isShowLogoutBtn: !this.isApp,
                    isShowSwitchPcBtn: !this.isApp
                },
                member: {
                    isShowMoreMenu: this.isApp
                }
            }
        };
    },
    initSysTBK: function() {
        this.sysSetting = {
            homeUrl: "#module/common/action/home",
            bodyClass: "tbk_style",
            isEnableCdn: this.cfg.cdnUrl ? true: false,
            orderMenuItems: [{
                id: "ty",
                name: "体育",
                items: [{
                    name: "系统体育",
                    id: "st"
                },
                {
                    name: "三昇体育",
                    id: "ts"
                },
                {
                    name: "新皇冠体育",
                    id: "ug"
                },
                {
                    name: "沙巴体育",
                    id: "sp"
                }]
            },
            {
                id: "sx",
                name: "视讯",
                items: [{
                    name: "AG国际馆",
                    id: "ag"
                },
                {
                    name: "BBIN馆",
                    id: "bb"
                },
                {
                    name: "HG名人馆",
                    id: "ho"
                },
                {
                    name: "OG东方馆",
                    id: "og"
                },
                {
                    name: "AB亚洲馆",
                    id: "ab"
                },
                {
                    name: "DS太阳城",
                    id: "ds"
                },
                {
                    name: "BG视讯厅",
                    id: "bv"
                }]
            },
            {
                id: "dz",
                name: "电子",
                items: [{
                    name: "MG电子",
                    id: "mg"
                },
                {
                    name: "PT电子",
                    id: "pt"
                },
                {
                    name: "HB电子",
                    id: "hb"
                },
                {
                    name: "YG电子",
                    id: "yg"
                },
                {
                    name: "BB电子",
                    id: "bg"
                }]
            },
            {
                id: "cp",
                name: "彩票",
                items: [{
                    name: "VR彩票",
                    id: "vr"
                }]
            },
            {
                id: "qp",
                name: "棋牌",
                items: [{
                    name: "VG斗地主",
                    id: "vg"
                },
                {
                    name: "AG捕鱼王",
                    id: "by"
                },
                {
                    name: "TBK棋牌",
                    id: "qp"
                },
                {
                    name: "开元棋牌",
                    id: "ky"
                }]
            }],
            homeIcon: {
                sport: "/app_static/images/menu_btns/hg_sports.png",
                jl: "/app_static/images/menu_btns/jl.png",
                jc: "/app_static/images/menu_btns/jl.png",
                hb: "/app_static/images/menu_btns/hb.png",
                yg: "/app_static/images/menu_btns/yg.png",
                ag: "/app_static/images/menu_btns/ag_ls.png",
                webchat: "/app_static/images/menu_btns/ocs.png",
                moreMenu: "/app_static/images/menu_btns/more.png",
                mg: "/app_static/images/menu_btns/mg.png",
                sp: "/app_static/images/menu_btns/sp.png",
                ho: "/app_static/images/menu_btns/ho.png",
                ab: "/app_static/images/menu_btns/ab.png",
                ds: "/app_static/images/menu_btns/ds.png",
                dc: "/app_static/images/menu_btns/dc.png",
                lo: "/app_static/images/menu_btns/dc.png",
                le: "/app_static/images/menu_btns/dc.png",
                bb: "/app_static/images/menu_btns/bbin.png",
                bg: "/app_static/images/menu_btns/bbin.png",
                pt: "/app_static/images/menu_btns/pt.png",
                ug: "/app_static/images/menu_btns/ug.png"
            },
            secondIcon: {
                sport: "/app_static/images/icons/hgty.png",
                sp: "/app_static/images/icons/sb.png",
                ts: "/app_static/images/icons/ss.png",
                jl: "/app_static/images/icons/jl.png",
                jc: "/app_static/images/icons/jl.png",
                ag: "/app_static/images/icons/ag.png",
                hb: "/app_static/images/icons/hb.png",
                mg: "/app_static/images/icons/mg.png",
                ho: "/app_static/images/icons/hg.png",
                yg: "/app_static/images/icons/yg.png",
                webchat: "/app_static/images/icons/zx.png",
                ab: "/app_static/images/icons/ab.png",
                ds: "/app_static/images/icons/ds.png",
                dc: "/app_static/images/icons/dc.png",
                lo: "/app_static/images/icons/dc.png",
                le: "/app_static/images/icons/dc.png",
                bb: "/app_static/images/icons/bbin.png",
                bg: "/app_static/images/icons/bbin.png",
                pt: "/app_static/images/icons/pt.png",
                ug: "/app_static/images/icons/ug.png"
            },
            mainIconClass: {
                tiyu: "glyphicon glyphicon-globe",
                caipiao: "glyphicon glyphicon-heart",
                shixun: "glyphicon glyphicon-facetime-video",
                dianzi: "glyphicon glyphicon-knight",
                wo: "glyphicon glyphicon-user",
                home: "glyphicon glyphicon-home",
                message: "glyphicon glyphicon-volume-up",
                money: "glyphicon glyphicon-credit-card",
                info: "glyphicon glyphicon-user",
                exchange: "glyphicon glyphicon-transfer",
                all: "glyphicon glyphicon-knight"
            },
            isPostMessageSetWindow: this.isApp,
            modules: {
                game: {
                    downloadMethod: this.isApp ? "openInApp": "",
                    openAppMethod: this.isApp ? "openApp": ""
                },
                memberExchange: {
                    tplId: "member_exchange_tbk"
                },
                common: {
                    isShowHomeHead: !this.isApp,
                    homeNoticeIconClass: "glyphicon glyphicon-volume-up notice-icon",
                    defaultLunbo: ["/app_static/images/carousel/tbk_0.png", "/app_static/images/carousel/tbk_1.png", "/app_static/images/carousel/tbk_2.png", "/app_static/images/carousel/tbk_3.png"],
                    defaultLogo: "/app_static/images/tbk_logo.png",
                    isShowLogoutBtn: !this.isApp,
                    isShowSwitchPcBtn: !this.isApp
                },
                member: {
                    isTransformNewWin: !this.isApp
                }
            }
        };
    },
    getCdnImgUrl: function(url) {
        if (this.sysSetting.isEnableCdn && !/^https?\:\/\//.test(url) && /\.(gif|jpg|png|jpeg)(\?.*)?$/i.test(url)) {
            var cdnUrl = this.cfg.cdnUrl;
            if (/^\//.test(url)) {
                url = cdnUrl + url;
            } else {
                var pathInfo = window.location.pathname.split("/");
                pathInfo[pathInfo.length - 1] = url;
                url = cdnUrl + pathInfo.join("/");
            }
        }
        return url;
    },
    parseTplHook: function(renderTxt) {
        var _this = this;
        renderTxt = renderTxt.replace(/(<img*.?src\s*=[\s\'\"]*)([^\s\'\"]+)([\s\'\"]*.*?>)/gi,
        function(t, r1, r2, r3) {
            return r1 + _this.getCdnImgUrl(r2) + r3;
        });
        return renderTxt;
    }
});